<?php

namespace App\Http\Controllers\Admin;


use App\Models\Video;
use Illuminate\Http\Request;

class VideoController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function batchget(Request $request){
        $query = Video::query();
        return ajaxReturn([
            'total'=>$query->count(),
            'items'=>$query->offset($request->input('offset',0))
                ->limit($request->input('count',15))
                ->orderByDesc('id')->get()
        ]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function save(Request $request){
        $video = Video::findOrNew($request->input('id'));
        $video->fill($request->input('video',[]))->save();
        return ajaxReturn(['video'=>$video]);
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delete(Request $request){
        Video::whereKey($request->input('items',[]))->delete();
        return ajaxReturn();
    }
}
